<?php
class lappembelian_model extends CI_Model{
	private $NoFaktur;
    private $DateFaktur;
    private $TotalAmount;
	private $Typebayar;
    private $Bankname;
  	private $Keterangan;
	private $NoPo;
	private $Quantity;
    private $Discount;
    private $Amount;
    private $createdby;
    private $createdon;
    private $lastupdateby;
  	private $lastupdateon;
  	private $active;
  	
  	private $tglAwal;
	private $tglAkhir;
	
	function setNoFaktur($nofaktur){
		$this->NoFaktur = $nofaktur;
	}

	function getNoFaktur(){
		return $this->NoFaktur;
	}
	
	function setDateFaktur($datefaktur){
		$this->DateFaktur = $datefaktur;
	}

	function getDateFaktur(){
		return $this->DateFaktur;
	}
	
	function setTotalAmount($ttlamount){
		$this->TotalAmount = $ttlamount;
	}

	function getTotalAmount(){
		return $this->TotalAmount;
	}
	
	function setTypebayar($typebyr){
		$this->Typebayar = $typebyr;
	}

	function getTypebayar(){
		return $this->Typebayar;
	}
	
	function setBankname($bankname){
		$this->Bankname = $bankname;
	}

	function getBankname(){
		return $this->Bankname;
	}
	
	function setKeterangan($ket){
		$this->Keterangan = $ket;
	}

	function getKeterangan(){
		return $this->Keterangan;
	}
	
	function setNoPo($nopo){
		$this->NoPo = $nopo;
	}

	function getNoPo(){
		return $this->NoPo;
	}
	
	function setQuantity($QTY){
		$this->Quantity = $QTY;
	}

	function getQuantity(){
		return $this->Quantity;
	}
	
	function setDiscount($discount){
		$this->Discount = $discount;
	}

	function getDiscount(){
		return $this->Discount;
	}
	
	function setAmount($amount){
		$this->Amount = $amount;
	}

	function getAmount(){
		return $this->Amount;
	}
	
	function setCreatedBy($c_by){
		$this->CreatedBy = $c_by;
	}

	function getCreatedBy(){
		return $this->CreatedBy;
	}

	function setCreatedOn(){
		$dateNow = date('Y-m-d H:i:s');
		$this->createdon = $dateNow;
	}

	function getCreatedOn(){
		return $this->createdon;
	}

	function setLastUpdateBy($u_by){
		$this->lastupdateby = $u_by;
	}

	function getLastUpdateBy(){
		return $this->lastupdateby;
	}

	function setLastUpdateOn(){
		$dateNow = date('Y-m-d H:i:s');
		$this->lastupdateon = $dateNow;
	}

	function getLastUpdateOn(){
		return $this->lastupdateon;
	}

	function setActive($active_val){
		$this->active = $active_val;
	}

	function getActive(){
		return $this->active;
	}
	
	function setTanggalAwal($tglAwal){
		$this->tglAwal = $tglAwal;
	}
	function getTanggalAwal(){
		return $this->tglAwal;
	}
	
	function setTanggalAkhir($tglAkhir){
		$this->tglAkhir = $tglAkhir;
	}
	function getTanggalAkhir(){
		return $this->tglAkhir;
	}
	// Call the module constructor
	function __construct(){
		parent::__construct();
	}
	
	function countGetList(){
		$tanggal=date('Y-m-d', strtotime('now'));
		$this->db->select("transaction_faktur_product_pembelian.NoFaktur,faktur_product_pembelian.DateFaktur,transaction_faktur_product_pembelian.NoPo,
		detail_product.Productname as nmbrgdet,transaction_faktur_product_pembelian.Quantity,transaction_faktur_product_pembelian.Discount,
		transaction_faktur_product_pembelian.Amount,faktur_product_pembelian.Keterangan,faktur_product_pembelian.CreatedBy")
		->join('faktur_product_pembelian', 'faktur_product_pembelian.NoFaktur=transaction_faktur_product_pembelian.NoFaktur')
		->join('transaction_order_product', 'transaction_order_product.NoPo=transaction_faktur_product_pembelian.NoPo')
		->join('detail_product', 'detail_product.KodeDetailBarang=transaction_faktur_product_pembelian.KodeDetailBarang')
		->where(array('faktur_product_pembelian.DateFaktur' => $tanggal,'faktur_product_pembelian.Active' => '1'))
		->group_by(array('faktur_product_pembelian.NoFaktur','transaction_faktur_product_pembelian.KodeDetailBarang'));
		$this->db->order_by('transaction_faktur_product_pembelian.NoFaktur', 'asc');
		$query = $this->db->get('transaction_faktur_product_pembelian');
		return $query->num_rows();
	}
	
	function getListlimit($limit,$start){
		$tanggal=date('Y-m-d', strtotime('now'));
		$this->db->select("transaction_faktur_product_pembelian.NoFaktur,faktur_product_pembelian.DateFaktur,transaction_faktur_product_pembelian.NoPo,
		detail_product.Productname as nmbrgdet,transaction_faktur_product_pembelian.Quantity,transaction_faktur_product_pembelian.Discount,
		transaction_faktur_product_pembelian.Amount,faktur_product_pembelian.Keterangan,faktur_product_pembelian.CreatedBy")
		->join('faktur_product_pembelian', 'faktur_product_pembelian.NoFaktur=transaction_faktur_product_pembelian.NoFaktur')
		->join('transaction_order_product', 'transaction_order_product.NoPo=transaction_faktur_product_pembelian.NoPo')
		->join('detail_product', 'detail_product.KodeDetailBarang=transaction_faktur_product_pembelian.KodeDetailBarang')
		->where(array('faktur_product_pembelian.DateFaktur' => $tanggal,'faktur_product_pembelian.Active' => '1'))
		->group_by(array('faktur_product_pembelian.NoFaktur','transaction_faktur_product_pembelian.KodeDetailBarang'))
		->limit($limit,$start);
		$this->db->order_by('transaction_faktur_product_pembelian.NoFaktur', 'asc');
		$query = $this->db->get('transaction_faktur_product_pembelian');
		return $query->result();
	}
	
	function getList(){
		$tanggal=date('Y-m-d', strtotime('now'));
		$this->db->select("transaction_faktur_product_pembelian.NoFaktur,faktur_product_pembelian.DateFaktur,
		transaction_faktur_product_pembelian.NoPo,detail_product.Productname as nmbrgdet,
		transaction_faktur_product_pembelian.Quantity,transaction_faktur_product_pembelian.Discount,
		transaction_faktur_product_pembelian.Amount,faktur_product_pembelian.Keterangan,faktur_product_pembelian.CreatedBy")
		->join('faktur_product_pembelian', 'faktur_product_pembelian.NoFaktur=transaction_faktur_product_pembelian.NoFaktur')
		->join('transaction_order_product', 'transaction_order_product.NoPo=transaction_faktur_product_pembelian.NoPo')
		->join('detail_product', 'detail_product.KodeDetailBarang=transaction_faktur_product_pembelian.KodeDetailBarang')
		->where(array('faktur_product_pembelian.DateFaktur' => $tanggal,'faktur_product_pembelian.Active' => '1'))
		->group_by(array('faktur_product_pembelian.NoFaktur','transaction_faktur_product_pembelian.KodeDetailBarang'));
        $query = $this->db->get('transaction_faktur_product_pembelian');
        return $query->result();
	}
	
	function getListtanggal() {
		$tglawl 	= date('Y-m-d', strtotime($this->getTanggalAwal()));
		$tglakhr	= date('Y-m-d', strtotime($this->getTanggalAkhir()));
		
		$query = $this->db->query("select A.NoFaktur,B.DateFaktur,A.NoPo,D.Productname as nmbrgdet,A.Quantity,A.Discount,
A.Amount,B.Keterangan,B.CreatedBy 
from transaction_faktur_product_pembelian A
inner join faktur_product_pembelian B on B.NoFaktur=A.NoFaktur
inner join transaction_order_product C on C.NoPo=A.NoPo
inner join detail_product D on D.KodeDetailBarang=A.KodeDetailBarang
where A.Active='1'  and B.DateFaktur between '".$tglawl."' and '".$tglakhr."'
GROUP BY B.NoFaktur, A.KodeDetailBarang");
		
        /*$this->db->select("transaction_faktur_product_pembelian.NoFaktur,faktur_product_pembelian.DateFaktur,transaction_faktur_product_pembelian.NoPo,
		detail_product.Productname as nmbrgdet,transaction_faktur_product_pembelian.Quantity,transaction_faktur_product_pembelian.Discount,
		transaction_faktur_product_pembelian.Amount,faktur_product_pembelian.Keterangan,faktur_product_pembelian.CreatedBy")
		->join('faktur_product_pembelian', 'faktur_product_pembelian.NoFaktur=transaction_faktur_product_pembelian.NoFaktur')
		->join('transaction_order_product', 'transaction_order_product.NoPo=transaction_faktur_product_pembelian.NoPo')
		->join('detail_product', 'detail_product.KodeDetailBarang=transaction_faktur_product_pembelian.KodeDetailBarang')
		->where ('faktur_product_pembelian.DateFaktur BETWEEN '.$tglawl.' AND '.$tglakhr.'')
		->group_by(array('faktur_product_pembelian.NoFaktur','transaction_faktur_product_pembelian.KodeDetailBarang'));
        $query = $this->db->get('transaction_faktur_product_pembelian');*/
        return $query->result();
    }
	
	function getLisnofaktur() {		
        $this->db->select("transaction_faktur_product_pembelian.NoFaktur,faktur_product_pembelian.DateFaktur,
		transaction_faktur_product_pembelian.NoPo,detail_product.Productname as nmbrgdet,
		transaction_faktur_product_pembelian.Quantity,transaction_faktur_product_pembelian.Discount,
		transaction_faktur_product_pembelian.Amount,faktur_product_pembelian.Keterangan,faktur_product_pembelian.CreatedBy")
		->join('faktur_product_pembelian', 'faktur_product_pembelian.NoFaktur=transaction_faktur_product_pembelian.NoFaktur')
		->join('transaction_order_product', 'transaction_order_product.NoPo=transaction_faktur_product_pembelian.NoPo')
		->join('detail_product', 'detail_product.KodeDetailBarang=transaction_faktur_product_pembelian.KodeDetailBarang')
		->where(array('faktur_product_pembelian.Active'=>'1'))->like(array('faktur_product_pembelian.NoFaktur' => $this->getNoFaktur()))
		->group_by(array('faktur_product_pembelian.NoFaktur','transaction_faktur_product_pembelian.KodeDetailBarang'));
        $query = $this->db->get('transaction_faktur_product_pembelian');
        return $query->result();
    }
}